package com.android.presenter.info;

import com.android.model.entity.res.UserVerifierResult;
import com.android.model.info.UserModel;
import com.android.model.net.HttpObserver;
import com.android.presenter.base.BasePresenter;
import com.android.presenter.iview.IUserVerifyView;
import com.android.util.log.LogUtil;

/**
 * author:  TenFace
 * date:    2017/9/27
 * description: 发送验证码
 */

public class UserVerifyPresenter extends BasePresenter<IUserVerifyView> {

    private static final String TAG = UserVerifyPresenter.class.getSimpleName();
    private UserModel mUserModel;

    public UserVerifyPresenter(IUserVerifyView iUserVerifyView) {
        super(iUserVerifyView);
        mUserModel = UserModel.getInstance();
    }

    public void userVerify(String phone) {
        mUserModel.userVerify(phone, new HttpObserver<UserVerifierResult>() {
            @Override
            public void onSuccess(UserVerifierResult userVerifierResult) {
                LogUtil.e(TAG, "校验成功，该用户已经注册！");
                if (mIView != null) {
                    mIView.userVerifySuccess(userVerifierResult);
                }
            }

            @Override
            public void onError(int errType, String errMessage) {
                LogUtil.e(TAG, "校验失败，失败码：" + errType + "--》》信息：" + errMessage);
                if (mIView != null) {
                    mIView.userVerifyFail(errType, errMessage);
                }
            }
        }, mIView.getLifeSubject());
    }

}
